package Sort;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2024/8/26-上午10:29
 * Since  :   1.0
 * Version:   1.0
 */
public class InsertSort {

    public static int[] insert(int[] arr) {
        for (int i = 1; i < arr.length - 1; i++) {
            int index = i - 1;
            int val = arr[i];

            if (index >= 0 && val < arr[index]) {
                arr[index + 1] = arr[index];
                index--;
            }

            arr[index + 1] = val;

        }
        return arr;
    }

    public static void main(String[] args) {
        int[] input1 = {5, 2, 9, 1, 5, 6};
        int[] input12 = InsertSort.insert(input1);
        System.out.println(input12.toString());
    }
}
